package leetcode;

public class kuaileshu {
    public int sum(int n){
        int sum=0;
        while(n!=0){
            int t=n%10;
            sum=sum+t*t;
            n=n/10;
        }
        return sum;
    }
    public boolean isHappy(int n) {
        //明确一点，一定 会有环的
        //定义快慢指针
        int slow=n;
        int fast=sum(n);
        while(slow!=fast){
            slow=sum(slow);
            fast=sum(sum(fast));
        }
        return slow==1;
    }

    public static void main(String[] args) {
        int n=19;
        kuaileshu kuaileshu=new kuaileshu();
        int sum = kuaileshu.sum(n);
        System.out.println(sum);
        boolean flg=kuaileshu.isHappy(n);
        System.out.println(flg);


    }
}
